home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Tools - Objects / MacsBug / MacsBug 6.2.1 / dcmds / C Samples / Echo.c < prev    next >
Text File  |  1991-05-01  |  2KB  |  78 lines

  1. /* Echo.c
  2.  
  3.    The following MPW commands will build the dcmd and copy it to the
  4.    "Debugger Prefs" file in the System folder. The dcmd's name in
  5.    MacsBug will be the name of the file built by the Linker.
  6.  
  7.         C Echo.c
  8.         Link {dcmdLib}dcmdGlue.a.o Echo.c.o {dcmdLib}DRuntime.o {CLibraries}StdCLib.o -o Echo
  9.         BuildDcmd Echo 101
  10.         Echo 'include "Echo";'    |    Rez -a -o "{systemFolder}Debugger Prefs"
  11.  */
  12.  
  13. #include <Types.h>
  14. #include "dcmd.h"
  15.  
  16.  
  17. void NumberToHex (long number, Str255 hex)
  18. {
  19.     Str255    digits = "0123456789ABCDEF";
  20.     int        n;
  21.  
  22.     strcpy (hex, &".00000000");
  23.     hex[0] = 8;
  24.     for (n = 8; n >= 1; n--)
  25.         {
  26.         hex[n] = digits[number % 16];
  27.         number = number / 16;
  28.         }
  29. } // NumberToHex
  30.  
  31.  
  32. pascal void CommandEntry (dcmdBlock* paramPtr)
  33. {
  34.     short    pos, ch;
  35.     long    value;
  36.     Boolean    ok;
  37.     Str255    str;
  38.  
  39.     switch (paramPtr->request)
  40.         {
  41.         case dcmdInit:
  42.             break;
  43.  
  44.         case dcmdHelp:
  45.             dcmdDrawLine ("\pECHO [params...]");
  46.             dcmdDrawLine ("\p   Echo the command line parameters");
  47.             break;
  48.  
  49.         case dcmdDoIt:
  50.             do {
  51.                 // Save the position so we can rewind if we get an error
  52.                 pos = dcmdGetPosition ();
  53.                 ch  = dcmdPeekAtNextChar ();
  54.                 if (((ch >= 'A') && (ch <= 'Z')) || ((ch >= 'a') && (ch <= 'z')))
  55.                     { // Get the parameter as a text string
  56.                     ch = dcmdGetNextParameter (str);
  57.                     dcmdDrawLine (str);
  58.                     }
  59.                 else
  60.                     { // Get the parameter as a 32 bit value
  61.                     ch = dcmdGetNextExpression (&value, &ok);
  62.                     if (ok)
  63.                         { // The expression was parsed correctly
  64.                         NumberToHex (value, str);
  65.                         dcmdDrawLine (str);
  66.                         }
  67.                     else
  68.                         { // The expression contained an error. Get it as a string
  69.                         dcmdSetPosition (pos);
  70.                         ch = dcmdGetNextParameter (str);
  71.                         dcmdDrawLine (str);
  72.                         }
  73.                     }
  74.             } while (ch != '\n');
  75.             break;
  76.         }
  77. } // CommandEntry
  78.